import re


class APICase:

    def replace_data(self, my_string):
        """替换 #。。# 标记"""
        result = re.finditer('#(.+?)#', my_string)
        for el in result:
            target = el.group()  # #smsflag#
            prop = el.group(1)  #
            value = getattr(self, prop)
            my_string = my_string.replace(target, value)
        return my_string


if __name__ == '__main__':
    case = APICase()

    # 准备需要替换的新的数据
    case.smsflag = 'abc'
    case.mobile = '181.....'
    case.username = 'yuz'

    my_string = """{"appType":3,"checkRegisterSmsFlag": "#smsflag#",
                    "mobile": "#mobile#",
                    "userName":"#username#",
                    "password":"123456",
                    "registerOrBind":1,
                    "validateType":1}"""
    new_string = case.replace_data(my_string)
    print(new_string)